//
//  ShareDetailsView.m
//  phmall
//
//  Created by admin on 2017/12/9.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "ShareDetailsView.h"

@implementation ShareDetailsView

-(instancetype)init{
    if (self=[super init]) {
        self.backgroundColor =[UIColor whiteColor];
        self.head=[[UIImageView alloc]init];
        [self addSubview:self.head];
        self.head.image=[UIImage imageNamed:@"图片"];
        self.head.layer.cornerRadius = 5;
        
        self.name=[[UILabel alloc] init];
        self.name.text=@"玛丽苏";
        self.name.font=[UIFont systemFontOfSize:15];
        [self addSubview:self.name];
        
        self.time=[[UILabel alloc] init];
        [self addSubview:self.time];
        self.time.font=[UIFont systemFontOfSize:13];
        self.time.textColor=[UIColor colorWithHexString:@"#c5c5c5"];
        self.time.text=@"发布时间:2017-08-17";
        
        self.addFriends=[UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:self.addFriends];
        [self.addFriends setTitle:Localized(@"添加好友") forState:UIControlStateNormal];
        [self.addFriends addTarget:self action:@selector(addFriendsAction) forControlEvents:UIControlEventTouchUpInside];
        [self.addFriends setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.addFriends setTitleColor:[UIColor colorWithHexString:@"#adadad"] forState:UIControlStateSelected];
        self.addFriends.titleLabel.font=[UIFont systemFontOfSize:13];
        [self.addFriends setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        ViewBorderRadius(self.addFriends, 5, 1, [UIColor orangeColor]);
        self.addFriends.backgroundColor=[UIColor whiteColor];
        [self.addFriends setTitleColor:[UIColor colorWithHexString:@"#adadad"] forState:UIControlStateSelected];
        //轮播图
        _scrollView = [[SDCycleScrollView alloc] init];
        _scrollView.autoScrollTimeInterval=5;
        _scrollView.pageControlStyle=SDCycleScrollViewPageContolStyleClassic;
        _scrollView.pageControlDotSize=CGSizeMake(6, 6);
        _scrollView.bannerImageViewContentMode=UIViewContentModeRedraw;
        _scrollView.pageDotColor=[UIColor blackColor];
        _scrollView.placeholderImage= [UIImage imageNamed:@"图片空白页"];
        _scrollView.currentPageDotColor=[UIColor orangeColor];
        [self addSubview:_scrollView];
        _scrollView.delegate=self;
      
    
//        NSMutableArray *cycle=[[NSMutableArray alloc] init];
//        for (DefaultModel *sModel in self.model.default_wap_flash)
//        {
//            [cycle addObject:[NSString stringWithFormat:@"%@%@",IMGURL,sModel.pic]];
//        }
//        _scrollView.imageURLStringsGroup=cycle;
        _scrollView.bannerImageViewContentMode=UIViewContentModeScaleToFill;
        self.price=[[UILabel alloc] init];
        [self addSubview:self.price];
        self.price.font=[UIFont systemFontOfSize:13];
        self.price.textColor=[UIColor orangeColor];
        self.price.text=@"₱99999";
    
        self.purchase=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.purchase addTarget:self action:@selector(purchaseAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.purchase];
        [self.purchase setTitle:Localized(@"去购买") forState:UIControlStateNormal];
        self.purchase.titleLabel.font=[UIFont systemFontOfSize:12];
        self.purchase.backgroundColor=[UIColor orangeColor];
        [self.purchase setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        ViewBorderRadius(self.purchase, 5, 0, [UIColor clearColor]);
        
        self.title=[[UILabel alloc] init];
        [self addSubview:self.title];
        self.title.font=[UIFont systemFontOfSize:15];
        self.title.numberOfLines=0;
        self.title.text=@"获取指定宽度width,字体大小fontSize,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度";
        
        self.message=[[UILabel alloc] init];
        self.message.numberOfLines=0;
        self.message.text=@"晒单理由:晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由晒单理由";
        self.message.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.message.font=[UIFont systemFontOfSize:15];
        [self addSubview:self.message];
        
//        self.sales=[[UILabel alloc] init];
//        self.sales.numberOfLines=0;
//        self.sales.text=@"销量:10件";
//        self.sales.font=[UIFont systemFontOfSize:13];
//        [self addSubview:self.sales];
        
        self.like=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.like setImage:[UIImage imageNamed:@"喜欢点赞"] forState:UIControlStateSelected];
        [self.like setImage:[UIImage imageNamed:@"喜欢未点"] forState:UIControlStateNormal];
        [self.like setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        [self.like setTitleColor:[UIColor colorWithHexString:@"#adadad"] forState:UIControlStateNormal];
        [self.like setTitle:[NSString stringWithFormat:@"%@%@",@"1000",Localized(@"人喜欢")] forState:UIControlStateNormal];
        self.like.titleLabel.font=[UIFont systemFontOfSize:13];
        [self.like addTarget:self action:@selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.like];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.head mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(10);
        make.width.height.offset(50);
    }];
    ;
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.head.mas_right).offset(5);
        make.top.equalTo(self.head).offset(5);
    }];

    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.name);
        make.bottom.equalTo(self.head).offset(-5);
    }];

    [self.addFriends mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.width.offset(80);
        make.height.offset(25);
        make.centerY.equalTo(self.head);
    }];

    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.head.mas_bottom).offset(10);
        make.left.offset(0);
        make.width.offset(SCREEN_WIDTH);
        //make.height.offset(200).priorityHigh();
        make.height.offset(SCREEN_WIDTH);
    }];

    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView.mas_bottom).offset(10);
        make.left.offset(10);
    }];
    
    [self.purchase mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.width.offset(55);
        make.centerY.equalTo(self.price);
    }];
    
    self.title.preferredMaxLayoutWidth = SCREEN_WIDTH-20;
    [self.title setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    self.title.numberOfLines =0;
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.price.mas_bottom).offset(20).priorityHigh();
        make.left.offset(10).priorityHigh();
        make.width.offset(SCREEN_WIDTH-20);
    }];
    
    [self.message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom).offset(10);
        make.left.offset(10);
        make.width.offset(SCREEN_WIDTH-20);
    }];
    
//    [self.sales mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.message.mas_bottom).offset(10);
//        make.left.offset(10);
//    }];
    
    [self.like mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.message.mas_bottom).offset(10);
        make.left.offset(20);
    }];
    [self.like layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:10];
}

-(void)addFriendsAction{
    if (self.delegate&&[self.delegate respondsToSelector:@selector(addFriends:)]) {
        [self.delegate addFriends:self.model.m_uid];
    }
}
-(void)purchaseAction{
    if (self.delegate&&[self.delegate respondsToSelector:@selector(purchase:)]) {
        [self.delegate purchase:self.model.g_uid];
    }
}
-(void)likeAction:(UIButton *)sender{
   
    if (sender.selected) {
        NSLog(@"你已经点过啦");
        return;
    }
    sender.selected=YES;
    NSInteger like=[sender.titleLabel.text intValue];
    
    like++;
    [self.like setTitle:[NSString stringWithFormat:@"%ld %@",(long)like,Localized(@"人喜欢")] forState:UIControlStateNormal];
    
    if (self.delegate&&[self.delegate respondsToSelector:@selector(likeAction:)]) {
        [self.delegate likeAction:self.model.uid];
    }
}

-(void)setModel:(ShareModel *)model{
    _model=model;
    NSLog(@"%lu",(unsigned long)self.model.pics.count);
    self.name.text=model.member_id;
    [self.head sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMGURL,model.member_image]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    self.time.text=model.register_date;
    self.message.text=model.comment;
    self.title.text=model.goods_name;
    [self.like setTitle:[NSString stringWithFormat:@"%@ %@",model.love,Localized(@"人喜欢")] forState:UIControlStateNormal];
    self.like.selected=model.like;

    self.price.text=[NSString stringWithFormat:@"₱%@",model.buy_price];
    self.addFriends.selected= [model.is_friend isEqualToString:@"0"]? NO : YES;
    ViewBorderRadius(self.addFriends, 5, 1, [model.is_friend isEqualToString:@"0"]? [UIColor orangeColor] : [UIColor colorWithHexString:@"#adadad"]);

    NSMutableArray *cycle=[[NSMutableArray alloc] init];
    for (NSString *str in self.model.pics)
    {
        [cycle addObject:[NSString stringWithFormat:@"%@%@",IMGURL,str]];
    }
    _scrollView.imageURLStringsGroup=cycle;

}
@end
